package com.lyf.scm.admin.domain.remote.purchase.facade;

import com.alibaba.fastjson.JSON;
import com.lyf.scm.admin.domain.remote.purchase.PurchaseRemote;
import com.lyf.scm.admin.domain.remote.purchase.dto.PlanPoInfoDTO;
import com.lyf.scm.admin.domain.remote.purchase.dto.PlanPoQueryDTO;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 采购中心
 *
 * @author wangchlei
 * @date 2020/08/27
 */
@Service
@Slf4j
public class PurchaseFacade {
    @Resource
    private PurchaseRemote purchaseRemote;

    /**
     * 查询sku在指定周期内的已接收量
     *
     * @param planPoQueryDTO
     * @return {@link List<PlanPoInfoDTO>}
     **/
    public List<PlanPoInfoDTO> getReceivedQty(PlanPoQueryDTO planPoQueryDTO) {
        log.info("调用采购中心查询实际收货量入参:planPoQueryDTO:{}", JSON.toJSONString(planPoQueryDTO));
        Response<List<PlanPoInfoDTO>> response = purchaseRemote.getReceivedQty(planPoQueryDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public List<PlanPoInfoDTO> listAppointmentQty(PlanPoQueryDTO planPoQueryDTO){
        log.info("调用采购中心查询预约在途量入参:planPoQueryDTO:{}", JSON.toJSONString(planPoQueryDTO));
        Response<List<PlanPoInfoDTO>> response = purchaseRemote.listAppointmentQty(planPoQueryDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public List<PlanPoInfoDTO> listNoAgreementQty(PlanPoQueryDTO planPoQueryDTO){
        log.info("调用采购中心查询未履约采购量入参:planPoQueryDTO:{}", JSON.toJSONString(planPoQueryDTO));
        Response<List<PlanPoInfoDTO>> response = purchaseRemote.listNoAgreementQty(planPoQueryDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
